package cn.hss.object.dt;

import sun.misc.ClassLoaderUtil;

import java.util.Random;

/**
 * @author 作者：HeShaoShuai
 * @Email 邮箱：2569819541@qq.com
 * @Date 日期：2023/4/25 17:18
 * @Package 包名：cn.hss.object.dt
 * @Project 项目名：JavaSE
 * @Version 1.0
 */
public class Animal {
private String name="灰太狼";
public void eat(){
		System.out.println("animal eat food");
		}
public void run(){
		System.out.println("灰太狼蹦蹦跳跳的回家了。。。");
		}

public String getName() {
		return name;
		}

public void setName(final String name) {
		this.name = name;
		}

//解决养猫、养狗
public static Animal getInstance(int key){
		switch (key){
		case 0:
		return new Cat();
		case 1:
		return new Dog();
default:
		return new Animal();
		}
		}

public static void main(String[] args) {
		int key=new Random().nextInt(3);
		Animal animal = getInstance(key);
        /*key =0
        Animal animal =new Cat();//向上造型
        key =1
        Animal animal =new Dog();
        * */
		animal.eat();//运行期绑定
		animal.run();
		System.out.println(animal.name);//说明成员变量没有多态性
		}
}
